from django.http import HttpResponse
from django.utils import simplejson
from django.views.decorators.csrf import csrf_exempt

from base.lib import *
from books.models import Themes
from books.models import DataHandler

@csrf_exempt
@ajax
def tree(request):        
    handler = DataHandler()
    book_id = int(request.POST["book_id"])
    parent_id = 0 if request.POST["id"] == "init" else int(request.POST["id"])

    result = Themes.objects.all().filter(book_id=book_id, parent_id=parent_id)
    json = handler.build_json_response(result)    
    return HttpResponse(content=simplejson.dumps(json), mimetype='application/json')

@csrf_exempt
@ajax
def theme_content(request):
    pass